<template>
  <a-card :title="formTile + '封样明细'">
    <template #extra>
      <a-button type="primary" style="margin-left: 10px" @click="toPrint">打印</a-button>
      <a-button type="primary" style="margin-left: 10px" @click="getCraftList">查看尺寸单</a-button>
      <a-button type="primary" style="margin-left: 10px" @click="updateAndApprove">审核</a-button>
      <!-- <a-button type="primary" style="margin-left: 10px" @click="deApproveSealBill">反审核</a-button> -->
      <a-button type="primary" style="margin-left: 10px" @click="handleSubmit">保存</a-button>
    </template>
    <div class="main">
      <div class="steps-content">
        <a-row type="flex" justofy="start" align="top">
          <a-col span="24">
            <a-descriptions bordered :column="{ xxl: 4, xl: 3, lg: 3, md: 3, sm: 2, xs: 1 }">
              <a-descriptions-item label="单号">
                {{ billNo }}
              </a-descriptions-item>
              <a-descriptions-item label="单据状态">
                {{ fyDetail.billFlag }}
              </a-descriptions-item>
              <a-descriptions-item label="工艺单号">
                {{ fyDetail.ksBillNo }}
              </a-descriptions-item>
              <a-descriptions-item label="样衣号">
                {{ fyDetail.sampleCode }}
              </a-descriptions-item>
              <a-descriptions-item label="品名">
                {{ fyDetail.sampleName }}
              </a-descriptions-item>
              <a-descriptions-item label="品类">
                {{ fyDetail.sampleCat }}
              </a-descriptions-item>
              <a-descriptions-item label="品牌">
                {{ fyDetail.brand }}
              </a-descriptions-item>
              <a-descriptions-item label="款式">
                {{ fyDetail.styleId }}
              </a-descriptions-item>
              <a-descriptions-item label="波段">
                {{ fyDetail.band }}
              </a-descriptions-item>
              <a-descriptions-item label="厂家">
                {{ fyDetail.factory }}
              </a-descriptions-item>
              <a-descriptions-item label="封样日期">
                {{ fyDetail.audDate }}
              </a-descriptions-item>
              <a-descriptions-item label="封样人">
                {{ fyDetail.sealer }}
              </a-descriptions-item>
              <a-descriptions-item label="工艺师">
                {{ fyDetail.crafter }}
              </a-descriptions-item>
              <a-descriptions-item label="部门">
                {{ fyDetail.department }}
              </a-descriptions-item>
              <a-descriptions-item label="业务员">
                {{ fyDetail.auderYwy }}
              </a-descriptions-item>
              <a-descriptions-item label="品牌排名">
                {{ fyDetail.brandRank }}
              </a-descriptions-item>
            </a-descriptions>
            <a-card>
              <a-form :form="form" @submit="handleSubmit" :labelCol="FormItemLayout.labelCol" :wrapperCol="FormItemLayout.wrapperCol">
                <a-row>
                  <a-col :span="12">
                    <a-form-item label="是否重新封样" style="text-align: left" :label-col="{ span: 8 }" :wrapper-col="{ span: 12 }">
                      <a-checkbox :checked="fyDetail.isReSeal == 'Y'" v-decorator="[`isReSeal`, { validateTigger: ['change', 'blur'] }]" @change="isReSealChange()"> </a-checkbox>
                    </a-form-item>
                  </a-col>
                  <a-col :span="12">
                    <a-form-item label="重新封样原因" style="text-align: left" :label-col="{ span: 4 }" :wrapper-col="{ span: 12 }">
                      <a-select mode="multiple" style="width: 100%" placeholder="请选择" allow-clear v-decorator="[`reSealReason`, { validateTrigger: ['change', 'blur'] }]">
                        <a-select-option v-for="(item, i) in sealReasonList" :key="i" :value="item.name">
                          {{ item.name }}
                        </a-select-option>
                      </a-select>
                    </a-form-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :span="12">
                    <a-form-item label="发现问题类型" style="text-align: left" :label-col="{ span: 8 }" :wrapper-col="{ span: 12 }">
                      <a-select mode="multiple" style="width: 100%" placeholder="请选择" allow-clear v-decorator="[`problemType`, { validateTrigger: ['change', 'blur'] }]">
                        <a-select-option v-for="(item, i) in problemTypeList" :key="i" :value="item.name">
                          {{ item.name }}
                        </a-select-option>
                      </a-select>
                    </a-form-item>
                  </a-col>
                  <a-col :span="12">
                    <a-form-item label="齐码质量登记" style="text-align: left" :label-col="{ span: 4 }" :wrapper-col="{ span: 12 }">
                      <a-select mode="tag" style="width: 100%" placeholder="请选择" allow-clear v-decorator="[`qualitySign`, { validateTrigger: ['change', 'blur'] }]">
                        <a-select-option v-for="(item, i) in sizeQualityList" :key="i" :value="item.name">
                          {{ item.name }}
                        </a-select-option>
                      </a-select>
                    </a-form-item>
                  </a-col>
                </a-row>
                <a-form-item label="具体问题" style="text-align: left" :label-col="{ span: 4 }" :wrapper-col="{ span: 16 }">
                  <a-input allow-clear placeholder="请输入内容" v-decorator="[`specificProblem`, { validateTrigger: ['change', 'blur'] }]"> </a-input>
                </a-form-item>
                <a-form-item label="同意更改工厂优化工艺" style="text-align: left">
                  <a-input allow-clear placeholder="请输入内容" v-decorator="[`optimizeCraft`, { validateTrigger: ['change', 'blur'] }]"> </a-input>
                </a-form-item>
                <a-form-item label="备注" style="text-align: left">
                  <a-input allow-clear style="width: 100%" placeholder="请输入内容" v-decorator="[`remark`, { validateTrigger: ['change', 'blur'] }]" />
                </a-form-item>

                <a-form-item label="红扣样" style="text-align: left">
                  <a-input allow-clear placeholder="请输入内容" v-decorator="[`redButtonSample`, { validateTrigger: ['change', 'blur'] }]"> </a-input>
                </a-form-item>

                <a-form-item label="封样意见" style="text-align: left">
                  <a-textarea allow-clear :rows="15" placeholder="请输入内容" v-decorator="[`sealOpinion`, { validateTrigger: ['change', 'blur'] }]"> </a-textarea>
                </a-form-item>
              </a-form>
            </a-card>
            <a-card>
              <a-form :form="form" :labelCol="FormItemLayout.labelCol" :wrapperCol="FormItemLayout.wrapperCol">
                <a-row>
                  <a-col :span="12">
                    <a-form-item label="童装绳带确认" style="text-align: left" :label-col="{ span: 8 }" :wrapper-col="{ span: 12 }">
                      <a-select allow-clear placeholder="请选择" style="width: 100%" v-decorator="[`ropeConfirm`, { validateTrigger: ['change', 'blur'] }]">
                        <a-select-option v-for="(item, i) in ropeConfirmList" :key="i" :value="item.code">
                          {{ item.name }}
                        </a-select-option>
                      </a-select>
                      <!-- {{ fyDetail.ropeConfirm }} -->
                    </a-form-item>
                  </a-col>
                  <a-col :span="12">
                    <a-form-item label="齐码定位裁剪" style="text-align: left" :label-col="{ span: 4 }" :wrapper-col="{ span: 12 }">
                      <a-select allow-clear placeholder="请选择" v-decorator="[`locationClip`, { validateTrigger: ['change', 'blur'] }]">
                        <a-select-option v-for="(item, i) in locationClipList" :key="i" :value="item.code">
                          {{ item.name }}
                        </a-select-option>
                      </a-select>
                      <!-- {{ fyDetail.locationClip }} -->
                    </a-form-item>
                  </a-col>
                </a-row>
                <a-row>
                  <a-col :span="12">
                    <a-form-item label="齐码胶印" style="text-align: left" :label-col="{ span: 8 }" :wrapper-col="{ span: 12 }">
                      <a-select allow-clear placeholder="请选择" v-decorator="[`offsetPrint`, { validateTrigger: ['change', 'blur'] }]">
                        <a-select-option v-for="(item, i) in offsetPrintList" :key="i" :value="item.code">
                          {{ item.name }}
                        </a-select-option>
                      </a-select>
                      <!-- {{ fyDetail.offsetPrint }} -->
                    </a-form-item>
                  </a-col>
                  <a-col :span="12">
                    <a-form-item label="试穿确认" style="text-align: left" :label-col="{ span: 4 }" :wrapper-col="{ span: 12 }">
                      <a-select allow-clear placeholder="请选择" v-decorator="[`fittingConfirm`, { validateTrigger: ['change', 'blur'] }]">
                        <a-select-option v-for="(item, i) in fittingConfirmList" :key="i" :value="item.code">
                          {{ item.name }}
                        </a-select-option>
                      </a-select>
                      <!-- {{ fyDetail.fittingConfirm }} -->
                    </a-form-item>
                  </a-col>
                </a-row>
                <a-form-item label="版师意见" style="text-align: left">
                  {{ fyDetail.samplerOpinion }}
                </a-form-item>
                <a-form-item label="试穿不确认原因" style="text-align: left">
                  <a-select mode="multiple" allow-clear placeholder="请选择" v-decorator="[`unConfirmReason`, {validateTrigger:['change', 'blur' ]}]">
                    <a-select-option v-for="(item, i) in unConfirmReasonList" :key="i" :value="item.name">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
                <a-form-item label="试穿不确认具体原因" style="text-align: left">
                  <a-textarea allow-clear :rows="2" placeholder="请输入内容" v-decorator="[`unFittingReason`, { validateTrigger: ['change', 'blur'] }]"> </a-textarea>
                </a-form-item>
                <a-form-item label="重点工艺" style="text-align: left">
                  {{ fyDetail.importantCraft }}
                </a-form-item>
              </a-form>
            </a-card>
          </a-col>
        </a-row>
      </div>
      <div>
        <a-row style="border: 1px solid #f5f5f5; overflow: hidden">
          <a-col :span="4">
            <a-row class="lastTitle"> 单位:cm </a-row>
            <a-row>
              <a-col :span="4" class="contentT"> 序号 </a-col>
              <a-col :span="6" class="contentT"> 号型/部位 </a-col>
              <a-col :span="14" class="contentT"> 成衣测量说明 </a-col>
            </a-row>
            <a-row>
              <a-row v-for="(item, i) in SizeDetail" :key="i">
                <a-col :span="4" class="contentH">
                  <span>{{ i + 1 }}</span>
                </a-col>
                <a-col :span="6" class="contentH">
                  <span>{{ item.part }}</span>
                </a-col>
                <a-col :span="14" class="contentE">
                  <span>{{ item.clff }}</span>
                </a-col>
              </a-row>
            </a-row>
          </a-col>
          <a-col :span="20">
            <a-row class="lastTitle"> 成衣尺寸 </a-row>
            <a-row>
              <div style="display: flex; flex-wrap: wrap">
                <div v-for="(item, i) in sizeDetailList" :key="i" class="contentH" :style="{ width: `${100 / sizeDetailList.length}%` }">
                  {{ item.sizeid }}
                  <a-checkbox :checked="item.isPrint == 'Y' ? true : false" @change="e => updateSealPrintSize(e, item)"> </a-checkbox>
                </div>
              </div>
            </a-row>
            <a-row>
              <div style="display: flex; flex-wrap: wrap">
                <div v-for="(item, i) in sizeDetailList" :key="i" class="contentM" :style="{ width: `${100 / sizeDetailList.length}%` }">
                  <div>{{ item.model }}</div>
                </div>
              </div>
            </a-row>
            <a-row>
              <div style="display: flex; flex-wrap: wrap">
                <div v-for="(item, i) in sizeDetailList" :key="i" class="contentM" :style="{ width: `${100 / sizeDetailList.length}%` }" style="display: flex; justify-content: space-around">
                  <div class="contentM" style="width: 20%">尺寸</div>
                  <div class="contentM" style="width: 20%">偏差1</div>
                  <div class="contentM" style="width: 20%">偏差2</div>
                  <div class="contentM" style="width: 20%">偏差3</div>
                  <div class="contentM" style="width: 20%">偏差4</div>
                </div>
              </div>
            </a-row>
            <a-row>
              <div style="display: flex; flex-wrap: wrap" v-for="(item, i) in SizeDetail" :key="i">
                <div v-for="(subitem, index) in sizeDetailList" :key="index" class="contentH" :style="{ width: `${100 / sizeDetailList.length}%` }">
                  <div>
                    <div v-for="(x, i) in item.info" :key="i">
                      <a-input
                        v-if="x.sizeId == subitem.sizeid"
                        v-model="x.sizeNum"
                        class="inputRight"
                        @focus="onFocus"
                        @blur="e => onChange(e, item)"
                        type="number"
                        style="z-index: 100; width: 20%; padding: 0 3px; text-align: center"
                      />
                      <a-input
                        v-if="x.sizeId == subitem.sizeid"
                        v-model="x.diff"
                        class="inputRight"
                        @focus="onFocus"
                        @blur="e => onChange(e, item)"
                        type="string"
                        style="z-index: 100; width: 20%; padding: 0 3px; text-align: center"
                      />
                      <a-input
                        v-if="x.sizeId == subitem.sizeid"
                        v-model="x.diff2"
                        class="inputRight"
                        @focus="onFocus"
                        @blur="e => onChange(e, item)"
                        type="string"
                        style="z-index: 100; width: 20%; padding: 0 3px; text-align: center"
                      />
                      <a-input
                        v-if="x.sizeId == subitem.sizeid"
                        v-model="x.diff3"
                        class="inputRight"
                        @focus="onFocus"
                        @blur="e => onChange(e, item)"
                        type="string"
                        style="z-index: 100; width: 20%; padding: 0 3px; text-align: center"
                      />
                      <a-input
                        v-if="x.sizeId == subitem.sizeid"
                        v-model="x.diff4"
                        class="inputRight"
                        @focus="onFocus"
                        @blur="e => onChange(e, item)"
                        type="string"
                        style="z-index: 100; width: 20%; padding: 0 3px; text-align: center"
                      />
                    </div>
                  </div>
                </div>
              </div>
            </a-row>
          </a-col>
        </a-row>
      </div>
    </div>
    <!-- <div class="steps-action">
        <a-button type="primary" @click="reset">返回</a-button>
        <div>
        </div>
    </div> -->
    <a-modal title="查看尺寸单" :visible="showImport" width="70%" :footer="null" @cancel="closeImport()">
      <!-- <a-button type="primary" :disabled="hasSelected" @click="handleImport">确认导入</a-button> -->
      <a-table :scroll="{ x: 1500 }" :loading="loading" :columns="columnCraft" :pagination="pagination" :data-source="craftList" row-key="record=>record.id">
        <a slot="craftCode" slot-scope="txt, record" @click="toCraftBill(record)"> {{ txt }} </a>
        <template slot="action" slot-scope="txt, record">
          <a class="mr-10" @click="handleImport(record)">导入</a>
        </template>
      </a-table>
    </a-modal>
  </a-card>
</template>

<script>
import {
  getFyBillDetail,
  getDictChildList,
  getList,
  getSealSizeList,
  updateFyDet,
  importSealSize,
  getSizeList,
  updateSealSize,
  approveSealBill,
  unApproveSealBill,
  getSealSizeIsPrint,
  updateSealPrintSize
} from '@api/rd/index'

const column1 = [
  {
    title: '行号',
    dataIndex: 'seq'
  },
  {
    title: '部位',
    dataIndex: 'part'
  },
  {
    title: '测量方法',
    dataIndex: 'clff'
  }
]

const columnCraft = [
  {
    title: '工艺单号',
    width: 150,
    dataIndex: 'code',
    scopedSlots: { customRender: 'craftCode' }
  },
  {
    title: '单据编号',
    width: 100,
    dataIndex: 'billNo'
  },
  {
    title: '上货季',
    width: 100,
    dataIndex: 'scseason'
  },
  {
    title: '品牌',
    width: 100,
    dataIndex: 'brand'
  },
  {
    title: '小类',
    width: 100,
    dataIndex: 'xl'
  },
  {
    title: '样衣号',
    width: 100,
    dataIndex: 'sampleCode'
  },
  {
    title: '品名',
    width: 100,
    dataIndex: 'sampleName'
  },
  {
    title: '版次',
    width: 100,
    dataIndex: 'bc'
  },
  {
    title: '颜色',
    width: 100,
    dataIndex: 'stycolorid'
  },
  {
    title: '操作',
    width: 100,
    scopedSlots: { customRender: 'action' },
    fixed: 'right',
    align: 'center'
  }
]
export default {
  props: {
    content: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      id: '',
      column1,
      billNo: '',
      ksBillNo: '',
      showImport: false,
      isSync: false,
      //loading: false,
      disabled: false,
      nonError: true,
      idEdit: false,
      partBillId: '',
      partId: '',
      SizeDetail: [],
      fyDetail: {},
      craftList: [],
      //craftDetail: {},
      sealReasonList: [],
      problemTypeList: [],
      sizeQualityList: [],
      ropeConfirmList: [],
      locationClipList: [],
      offsetPrintList: [],
      fittingConfirmList: [],
      unConfirmReasonList: [],
      sizeDetailList: [],
      sizeIsPrint: [],
      subform: {},
      approveform: {},
      form: this.$form.createForm(this),
      FormItemLayout: {
        labelCol: {
          xl: { span: 4 }
        },
        wrapperCol: {
          xl: { span: 16 }
        }
      },
      loading: false,
      reloading: false,
      reloading: false,
      hasSelected: false,
      selectedRowKeys: [],
      selectionRows: [],
      columnCraft: columnCraft,
      pagination: {
        total: 0,
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30', '40'],
        showQuickJumper: true,
        showSizeChanger: true,
        showTotal: total => `共 ${total} 条记录`,
        itemRender: (current, type, originalElement) => {
          if (type === 'prev') {
            return <a>上一页</a>
          } else if (type === 'next') {
            return <a>下一页</a>
          }
          return originalElement
        }
      },
      billId: null,
      focusvalue: ''
    }
  },
  computed: {
    userInfo() {
      return this.$store.getters.userInfo || null
    }
  },
  mounted() {
    this.getDictChildList('SEAL_REASON', 'sealReasonList')
    this.getDictChildList('PROBLEM_TYPE', 'problemTypeList')
    this.getDictChildList('SIZE_QUALITY', 'sizeQualityList')
    this.getDictChildList('YESNO', 'ropeConfirmList')
    this.getDictChildList('YESNO', 'locationClipList')
    this.getDictChildList('OFFSET_PRINT', 'offsetPrintList')
    this.getDictChildList('YESNO', 'fittingConfirmList')
    this.getDictChildList('UN_CONFIRM_REASON', 'unConfirmReasonList')
    this.getSizeDetail()
  },
  created() {
    //const { content } = this.$props
    const billNo = this.$route.query.billNo
    const ksBillNo = this.$route.query.ksBillNo
    console.log(this.$route.query)
    if (billNo) {
      this.formTile = '编辑'
      this.billNo = billNo
      this.ksBillNo = ksBillNo
      this.$nextTick(() => {
        this.getfyDetail()
        this.disabled = true
        // this.getCraftList()
      })

      this.idEdit = true
    } else {
      this.$message.error('未获取到封样单号！')
    }
  },
  methods: {
    reload(){
      this.reloading = true
      this.$nextTick(() => {
        this.getfyDetail()
        this.reloading = false
      })
    },
    onFocus(e) {
      this.focusvalue = e.target.value
    },
    async onChange(e, item, type) {
      if (this.focusvalue != e.target.value && item.seq && item.part) {
        const { realname } = this.userInfo
        const params = item
        params.operator = realname
        // console.log(params)
        try {
          const res = await updateSealSize(params)
          if (res.code == 200) {
            // this.$message.success('保存成功！')
            // this.getBill()
          } else {
            if (res.msg) {
              this.$message.error(res.msg)
            } else {
              this.$message.error('保存失败！')
            }
          }
        } catch (error) {
          console.log(error)
          this.$message.error('保存失败！')
        }
      }
    },
    async onSelectedChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
    },
    async handleImport(record) {
      this.billId = record.id
      this.importSingleSealSize()
    },
    async reset() {
      this.form.resetFields()
      this.$router.push(`/seal/index`)
    },
    async getfyDetail() {
      const params = {
        billNo: this.billNo
      }
      try {
        const res = await getFyBillDetail(params)
        if (res.code == 200) {
          this.fyDetail = res.data
          if(this.fyDetail.billFlag == 'S' ){
            this.fyDetail.billFlag = '未审核'
          }else if(this.fyDetail.billFlag == 'Y' ){
            this.fyDetail.billFlag = '已审核'
          }else if(this.fyDetail.billFlag == '2' ){
            this.fyDetail.billFlag = '跟单'
          }else if(this.fyDetail.billFlag == '3' ){
            this.fyDetail.billFlag = '工艺'
          }
          this.getSizeList()
          this.isSync = this.fyDetail.isReSeal == '是' ? true : false
          this.form.setFieldsValue({
            remark: this.fyDetail.remark,
            //samplerOpinion: this.fyDetail.samplerOpinion,
            sealOpinion: this.fyDetail.sealOpinion,
            specificProblem: this.fyDetail.specificProblem,
            optimizeCraft: this.fyDetail.optimizeCraft,
            redButtonSample: this.fyDetail.redButtonSample,
            unFittingReason: this.fyDetail.unFittingReason,
            reSealReason: this.fyDetail.reSealReason ? this.fyDetail.reSealReason.split(',') : [],
            problemType: this.fyDetail.problemType ? this.fyDetail.problemType.split(',') : [],
            unConfirmReason: this.fyDetail.unConfirmReason ? this.fyDetail.unConfirmReason.split(',') : [],
            qualitySign: this.fyDetail.qualitySign,
            ropeConfirm: this.fyDetail.ropeConfirm,
            locationClip: this.fyDetail.locationClip,
            offsetPrint: this.fyDetail.offsetPrint,
            fittingConfirm: this.fyDetail.fittingConfirm
          })
        } else {
          if (res.msg) {
            this.$message.error(res.msg)
          } else {
            this.$message.error('获取封样单失败!')
          }
        }
      } catch (error) {
        this.$message.error('获取封样单失败!')
      }
    },
    toPrint(){
      this.$router.push({ path: '/seal/toprint', query:{ billNo: this.billNo, ksBillNo: this.ksBillNo, sampleCode: this.fyDetail.sampleCode}})
    },
    toCraftBill(record) {
      const routerData = this.$router.resolve({ path: '/rd/bill/detail', query: { id: record.id } })
      window.open(routerData.href, '_blank')
    },
    async getCraftList() {
      const params = {
        billNo: this.ksBillNo
      }
      try {
        const res = await getList('bill', params)
        if (res.code == 200) {
          this.craftList = res.data.records
          this.showImport = true
        } else {
          if (res.msg) {
            this.$message.error(res.msg)
          } else {
            this.$message.error('获取工艺单列表失败!')
          }
        }
      } catch (error) {
        this.$message.error('获取工艺单列表失败!')
      }
    },
    async importSingleSealSize(record) {
      const params = {
        billNo: this.billNo,
        billId: this.billId,
        operator: this.userInfo.realname
      }
      try {
        const res = await importSealSize(params)
        if (res.code == 200) {
          this.$message.success('导入成功！')
          this.showImport = false
          this.getSizeDetail()
        } else {
          if (res.msg) {
            this.$message.error(res.msg)
          } else {
            this.$message.error('导入失败！')
          }
        }
      } catch (error) {
        this.$message.error('导入失败！')
      }
    },
    async closeImport() {
      this.showImport = false
    },

    //获取部位尺码明细
    async getSizeDetail() {
      const params = {
        billNo: this.billNo
      }
      try {
        const res = await getSealSizeList(params)
        if (res.code == 200) {
          this.SizeDetail = res.data
          if (this.SizeDetail) {
            this.partBillId = this.SizeDetail[0].billId
            this.partId = this.SizeDetail[0].id
          }
        } else {
          if (res.msg) {
            this.$message.error(res.msg)
          } else {
            this.$message.error('获取部位信息失败!')
          }
        }
      } catch (error) {
        this.$message.error('获取部位信息失败!')
      }
    },
    async getSizeList() {
      const params = {
        sampleCode: this.fyDetail.sampleCode
      }
      console.log(this.fyDetail)
      try {
        const res = await getSizeList('c17', params)
        if (res.code == 200) {
          this.sizeDetailList = res.data
          this.getSealSizeIsPrint()
          console.log(this.sizeDetailList)
          // this.sizeDetailList.map((item)=>{
          //   item.model = item.model.replace("/","\n")
          // })
        } else {
          if (res.msg) {
            this.$message.error(res.msg)
          } else {
            this.$message.error('获取尺寸失败!')
          }
        }
      } catch (error) {
        this.$message.error('获取尺寸失败!')
      }
    },

    //获取数据字典
    async getDictChildList(name, list) {
      if (!this[list].length) {
        const params = {
          name: name
        }
        try {
          const res = await getDictChildList('dict', params)
          if (res.code == 200) {
            this[list] = res.data
          } else {
            if (res.msg) {
              this.$message.error(res.msg)
            } else {
              this.$message.error('获取数据字典失败！')
            }
          }
        } catch (error) {
          this.$message.error('获取数据字典失败！')
        }
      }
    },

    async isReSealChange() {
      console.log(this.fyDetail.isReSeal)
      if (this.fyDetail.isReSeal == 'Y') {
        this.fyDetail.isReSeal = 'N'
      } else {
        this.fyDetail.isReSeal = 'Y'
      }
    },

    async handleSubmit(e) {
      e.preventDefault()
      if (!this.fyDetail) {
        this.$message.error('保存失败！')
      } else {
        this.form.validateFields((err, values) => {
          if (!err) {
            this.subform = values
            this.submit()
          }
        })
      }
    },

    async submit() {
      var params = this.subform
      if (this.nonError) {
        const { realname } = this.userInfo
        params.operator = realname
        params.billNo = this.billNo
        console.log(params)
        if (this.id) {
          params.id = this.id
        }
        // params.reSealReason = params.reSealReason ? params.reSealReason.toString() : ''
        // params.problemType = params.problemType ? params.problemType.toString() : ''
        // params.qualitySign = params.qualitySign ? params.qualitySign.toString() : ''
        // params.brand = this.fyDetail.brand
        // params.billFlag = this.fyDetail.billFlag
        // params.ksBillNo = this.fyDetail.ksBillNo
        // params.sampleCode = this.fyDetail.sampleCode
        // params.sampleName = this.fyDetail.sampleName
        // params.sampleCat = this.fyDetail.sampleCat
        // params.band = this.fyDetail.band
        // params.styleId = this.fyDetail.styleId
        // params.audDate = this.fyDetail.audDate
        // params.sealer = this.fyDetail.sealer
        // params.crafter = this.fyDetail.crafter
        // params.department = this.fyDetail.department
        // params.auderYwy = this.fyDetail.auderYwy
        // params.brandRank = this.fyDetail.brandRank
        // params.isReSeal = this.fyDetail.isReSeal
        params.isReSeal = params.isReSeal ? 'Y' : 'N'
        params.problemType = params.problemType ? params.problemType.toString() : []
        params.reSealReason = params.reSealReason ? params.reSealReason.toString() : []
        params.unConfirmReason = params.unConfirmReason ? params.unConfirmReason.toString() : []
        if(this.fyDetail.billFlag == '未审核' ){
            this.fyDetail.billFlag = 'S'
          }else if(this.fyDetail.billFlag == '已审核' ){
            this.fyDetail.billFlag = 'Y'
          }else if(this.fyDetail.billFlag == '跟单' ){
            this.fyDetail.billFlag = '2'
          }else if(this.fyDetail.billFlag == '工艺' ){
            this.fyDetail.billFlag = '3'
          }
        Object.assign(this.fyDetail, params)
        try {
          const res = await updateFyDet(this.fyDetail)
          if (res.code == 200) {
            this.$message.success('封样单修改成功！')
          } else {
            this.$message.warning(res.msg)
          }
        } catch (error) {
          this.$message.warning('操作失败!')
        } finally {
          this.loading = false
        }
      }
    },

    // 审核封样单
    async approveSealBill() {
      const { realname } = this.userInfo
      const params = {
        billNo: this.billNo,
        operator: realname
      }
      console.log(params)
      try {
        const res = await approveSealBill(params)
        if (res.code == 200) {
          this.$message.success('审核成功！')
          this.$router.push({ path: '/seal/todet', query: { billNo: this.billNo, ksBillNo: this.ksBillNo }})
        } else {
          if (res.msg) {
            this.$message.warning(res.msg)
          } else {
            this.$message.warning('审核失败！')
          }
        }
      } catch(error) {
        console.log(error)
        this.$message.error('审核失败！')
      } finally {
        this.loading = false
      }
    },

    // 反审核方法
    // async deApproveSealBill(){
    //   const { realname } = this.userInfo
    //   const params = {
    //     billNo: this.billNo,
    //     operator: realname
    //   }
    //   console.log(params)
    //   try{
    //     const res = await unApproveSealBill(params)
    //     if(res.code == 200){
    //       this.$message.success('反审核成功')
    //       this.reload()
    //     }else{
    //       if(res.msg){
    //         this.$message.error(res.msg)
    //       }else{
    //         this.$message.error('反审核失败！')
    //       }
    //     }
    //   } catch(error) {
    //     this.$message.error('反审核失败！')
    //   } finally {
    //     this.loading = false
    //   }
    // },

    
    // 保存封样单并审核
    async updateAndApprove(e){
      e.preventDefault()
      if (!this.fyDetail) {
        this.$message.error('保存失败！')
      } else {
        this.form.validateFields((err, values) => {
          if (!err) {
            this.subform = values
            this.updateSealBill()
          }
        })
      }
    },
    async updateSealBill(){
      var params = this.subform
      if (this.nonError) {
        const { realname } = this.userInfo
        params.operator = realname
        params.billNo = this.billNo
        console.log(params)
        if (this.id) {
          params.id = this.id
        }
        params.isReSeal = params.isReSeal ? 'Y' : 'N'
        params.problemType = params.problemType ? params.problemType.toString() : []
        params.reSealReason = params.reSealReason ? params.reSealReason.toString() : []
        params.unConfirmReason = params.unConfirmReason ? params.unConfirmReason.toString() : []
        if(this.fyDetail.billFlag == '未审核' ){
            this.fyDetail.billFlag = 'S'
          }else if(this.fyDetail.billFlag == '已审核' ){
            this.fyDetail.billFlag = 'Y'
          }else if(this.fyDetail.billFlag == '跟单' ){
            this.fyDetail.billFlag = '2'
          }else if(this.fyDetail.billFlag == '工艺' ){
            this.fyDetail.billFlag = '3'
          }
        Object.assign(this.fyDetail, params)
        try {
          const res = await updateFyDet(this.fyDetail)
          if (res.code == 200) {
            //this.$message.success('封样单修改成功！')
            this.approveSealBill()
            
          } else {
            this.$message.warning(res.msg)
          }
        } catch(error) {
          this.$message.warning('操作失败!')
        } finally {
          // this.loading = false
          this.reload()
        }

      }
    },



    async getSealSizeIsPrint() {
      const params = {
        billNo: this.billNo
      }
      try {
        const res = await getSealSizeIsPrint(params)
        if (res.code == 200) {
          this.sizeIsPrint = res.data
          this.sizeDetailList.forEach((item, index) => {
            let isPrint = this.sizeIsPrint.filter(t => {
              return t.printSize == item.sizeid
            })
            if (isPrint.length > 0) {
              item.isPrint = isPrint[0].isPrint
            } else {
              item.isPrint = 'N'
            }
            this.$set(this.sizeDetailList, index, item)
          })
        } else {
          if (res.msg) {
            this.$message.warning(res.msg)
          } else {
            this.$message.warning('获取尺码失败！')
          }
        }
      } catch (error) {
        console.log(error)
        this.$message.warning('获取尺码失败！')
      }
    },
    async updateSealPrintSize(e, item) {
      e.target.checked = !e.target.checked
      if (item.isPrint == 'Y') {
        item.isPrint = 'N'
      } else {
        item.isPrint = 'Y'
      }
      if (this.billNo && item.sizeid) {
        const params = {}
        const { realname } = this.userInfo
        params.operator = realname
        params.billNo = this.billNo
        params.printSize = item.sizeid
        params.isPrint = item.isPrint
        params.id = item.id
        // params.isPrint = e.target.checked?'Y':'N'
        console.log(params)
        try {
          const res = await updateSealPrintSize(params)
          if (res.code == 200) {
            if (res.data) {
              item.id = res.data
            }
            this.sizeDetailList.forEach((t, index) => {
              if (t.sizeid == item.sizeid) {
                this.$set(this.sizeDetailList, index, item)
              }
            })
            this.$message.success('操作成功！')
          } else {
            if (res.msg) {
              this.$message.warning(res.msg)
            } else {
              this.$message.warning('操作失败！')
            }
          }
        } catch (error) {
          this.$message.warning('操作失败！')
        }
      }
    }
    //   e.preventDefault()
    //   if (!this.fyDetail) {
    //     this.$message.error('审核失败！')
    //   } else {
    //     this.form.validateFields((err, values) => {
    //       if (!err) {
    //         this.approveform = values
    //         this.approveSeal()
    //       }
    //     })
    //   }
    // },
    // async approveSeal() {
    //   var params = this.approveform
    //   if (this.nonError) {
    //     const { realname } = this.userInfo
    //     params.operator = realname
    //     params.billNo = this.billNo
    //     console.log(params)
    //     if (this.id) {
    //       params.id = this.id
    //     }
    //     params.isReSeal = params.isReSeal ? 'Y' : 'N'
    //     params.problemType = params.problemType ? params.problemType.toString() : []
    //     params.reSealReason = params.reSealReason ? params.reSealReason.toString() : []
    //     Object.assign(this.fyDetail, params)
    //     console.log(this.fyDetail)
    //     try {
    //       const res = await approveSealBill(this.fyDetail)
    //       if (res.code == 200) {
    //         this.$message.success('审核成功!')
    //       } else {
    //         if (res.msg) {
    //           this.$message.error(res.msg)
    //         } else {
    //           this.$message.error('审核失败!')
    //         }
    //       }
    //     } catch (error) {
    //       this.$message.warning('审核失败！')
    //     } finally {
    //       this.loading = false
    //     }
    //   }
    // }
  }
}
</script>

<style scoped>
.contentH {
  border: 1px solid #f5f5f5;
  height: 40px;
  font-size: 12px;
  text-align: center;
  line-height: 40px;
  font-weight: 500;
}
.contentE {
  border: 1px solid #f5f5f5;
  height: 40px;
  font-size: 12px !important;
  text-align: center;
  font-weight: 500;
  overflow: hidden;
}
.contentT {
  border: 1px solid #f5f5f5;
  height: 120px;
  font-size: 12px;
  text-align: center;
  line-height: 120px;
  font-weight: 500;
}
.contentM {
  border: 1px solid #f5f5f5;
  height: 40px;
  font-size: 12px;
  text-align: center;
  white-space: pre-line;
  line-height: 40px;
  font-weight: 500;
}
.lastTitle {
  font-size: 18px;
  font-weight: 500;
  background: #fafafa;
  line-height: 60px;
  border: 1px solid #f5f5f5;
  height: 60px;
  text-align: center;
}
.steps-content {
  margin-top: 16px;
  min-height: 200px;
  text-align: center;
  padding-top: 50px;
}
</style>
<style scoped>
.inputRight input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}
.inputRight input[type='number'] {
  -moz-appearance: textfield;
}
</style>